package com.jsyso.weixin.api;

import org.apache.commons.lang3.StringUtils;

import com.jsyso.jsyso.lang.JStringUtils;
import com.jsyso.jsyso.util.JsMap;

/**
 * 高级群发相关接口
 * @author janjan
 *
 */
public class MessageAPI extends API {
	public static enum MessageType {
		MPNEWS, TEXT, VOICE, IMAGE, VIDEO, WXCARD;
        public String get() {
            return this.name().toLowerCase();
        }
    }
	
	protected static String MASS_SEND = "/cgi-bin/message/mass/send?access_token=";
	
	
	protected static String TEMPLATE_SEND = "/cgi-bin/message/template/send?access_token=";
	
	public API templateSend(String appid, String jsonStr) {
		JsMap resMap = AccessTokenAPI.getAccessToken(appid);
		String accessToken = resMap.get("access_token", String.class);
		if(StringUtils.isNotBlank(accessToken)) {
			this.method = RequestMethod.POST;
			this.postData = jsonStr;
			this.url = JStringUtils.newBuilder(API_WEIXIN_QQ_COM, TEMPLATE_SEND, accessToken).toString();
		}
		if(logger.isDebugEnabled()) {
			logger.debug("[发送模板消息]postData=" + (this.postData));
		}
		return this;
	}
	
}
